import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier

# 1.获取数据集
# 2.数据基本处理
# 3.特征工程
# 4.机器学习(模型训练)
# 5.模型评估

# 1.获取数据集
iris = load_iris()
# 2.数据基本处理
x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.2, random_state=20)
# 3.特征工程
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.fit_transform(x_test)
# print("每一列特征的平均值：\n", transfer.mean_)
# print("每一列特征的方差：\n", transfer.var_)
# 4.机器学习(模型训练)
estimater = KNeighborsClassifier(n_neighbors=5)
estimater.fit(x_train, y_train)
# 5.模型评估
y_pre = estimater.predict(x_test)
print("预测结果为：\n", y_pre == y_test)
print("预测准确率为：\n", estimater.score(x_test, y_test))
